import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'index',
      meta: {
        title: '邻客充电桩-当前充电情况'
      },
      component: () => import('../pages/index')
    },
    {
      path: '/device',
      name: 'device',
      meta: {
        title: '邻客充电桩-开始充电'
      },
      component: () => import('../pages/device')
    },
    {
      path: '/pay',
      name: 'pay',
      meta: {
        title: '邻客充电桩-支付下单'
      },
      component: () => import('../pages/pay')
    },
    {
      path: '/register',
      name: 'register',
      meta: {
        title: '邻客充电桩-注册'
      },
      component: () => import('../pages/register')
    },
    {
      path: '/mine',
      name: 'mine',
      meta: {
        title: '邻客充电桩-个人中心'
      },
      component: () => import('../pages/mine')
    },
    {
      path: '/order',
      name: 'order',
      meta: {
        title: '邻客充电桩-消费记录'
      },
      component: () => import('../pages/order')
    },
    {
      path: '/orderDetail',
      name: 'orderDetail',
      meta: {
        title: '邻客充电桩-消费详情'
      },
      component: () => import('../pages/orderDetail')
    }
  ]
});

router.beforeEach((to, from, next) => {
  // to为向后走的路由对象，包括路由的完整信息
  // from为从哪跳来的路由对象
  // next()控制路由向下走，重新定义路由跳转的路由next(‘路由路径)
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next();
});

export default router;
